/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BibliotekaSzkolna.java
 *
 * Created on 2012-06-10, 21:06:26
 */
package pak;

/**
 *
 * @author Radek
 */
public class BibliotekaSzkolna extends javax.swing.JFrame {

    CSystemLogowania csl = null;
    
    /** Creates new form BibliotekaSzkolna */
    public BibliotekaSzkolna() {
        initComponents();
        csl = new CSystemLogowania();
        zalogowanyPanel.setVisible(false);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BladDialog = new javax.swing.JDialog();
        jPanel2 = new javax.swing.JPanel();
        bladLabel = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        loginPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        LoginTextField = new javax.swing.JTextField();
        PasswordField = new javax.swing.JPasswordField();
        jLabel2 = new javax.swing.JLabel();
        ZalogujButton = new javax.swing.JButton();
        zalogowanyPanel = new javax.swing.JPanel();
        wylogujButton = new javax.swing.JButton();
        zalogowanyLabel = new javax.swing.JLabel();

        BladDialog.setTitle("Logowanie - informacja");
        BladDialog.setAlwaysOnTop(true);
        BladDialog.setMinimumSize(new java.awt.Dimension(400, 150));
        BladDialog.setModal(true);

        bladLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        bladLabel.setText("Błąd logowania. Sprawdz login i hasło!");

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(153, 153, 153)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(159, Short.MAX_VALUE))
            .addComponent(bladLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(bladLabel)
                .addGap(27, 27, 27)
                .addComponent(jButton1)
                .addContainerGap(35, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout BladDialogLayout = new javax.swing.GroupLayout(BladDialog.getContentPane());
        BladDialog.getContentPane().setLayout(BladDialogLayout);
        BladDialogLayout.setHorizontalGroup(
            BladDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        BladDialogLayout.setVerticalGroup(
            BladDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Biblioteka szkolna");

        loginPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder()), "Logowanie", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.TOP));

        jLabel1.setText("Login:");

        jLabel2.setText("Hasło:");

        ZalogujButton.setText("Zaloguj");
        ZalogujButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ZalogujButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout loginPanelLayout = new javax.swing.GroupLayout(loginPanel);
        loginPanel.setLayout(loginPanelLayout);
        loginPanelLayout.setHorizontalGroup(
            loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(loginPanelLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(loginPanelLayout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(ZalogujButton))
                    .addGroup(loginPanelLayout.createSequentialGroup()
                        .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(LoginTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(PasswordField))))
                .addContainerGap(29, Short.MAX_VALUE))
        );
        loginPanelLayout.setVerticalGroup(
            loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(loginPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LoginTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
                .addComponent(ZalogujButton)
                .addContainerGap())
        );

        wylogujButton.setText("Wyloguj");
        wylogujButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wylogujButtonActionPerformed(evt);
            }
        });

        zalogowanyLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout zalogowanyPanelLayout = new javax.swing.GroupLayout(zalogowanyPanel);
        zalogowanyPanel.setLayout(zalogowanyPanelLayout);
        zalogowanyPanelLayout.setHorizontalGroup(
            zalogowanyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(zalogowanyPanelLayout.createSequentialGroup()
                .addGroup(zalogowanyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(zalogowanyPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(zalogowanyLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(zalogowanyPanelLayout.createSequentialGroup()
                        .addGap(76, 76, 76)
                        .addComponent(wylogujButton)))
                .addContainerGap(55, Short.MAX_VALUE))
        );
        zalogowanyPanelLayout.setVerticalGroup(
            zalogowanyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, zalogowanyPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(zalogowanyLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 16, Short.MAX_VALUE)
                .addGap(28, 28, 28)
                .addComponent(wylogujButton)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(184, 184, 184)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(zalogowanyPanel, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(loginPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(219, 219, 219))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(loginPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(zalogowanyPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(44, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void ZalogujButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ZalogujButtonActionPerformed
    if((!LoginTextField.getText().equals(""))&&(!PasswordField.getText().equals("")))
    {
        csl.weryfikujUzytkownika(LoginTextField.getText(), PasswordField.getText());
        if (csl.czyZalogowany())
        {
            bladLabel.setText("Zalogowano jako: " + csl.pobierzLogin() + " (" + csl.pobierzUprawnieniaUzytkownika() + ")");
            BladDialog.setVisible(true);
            loginPanel.setVisible(false);
            zalogowanyLabel.setText("Zalogowano jako: " + csl.pobierzLogin() + " (" + csl.pobierzUprawnieniaUzytkownika() + ")");
            zalogowanyPanel.setVisible(true);
        }
        else
        {
            LoginTextField.setText("");
            PasswordField.setText("");
            bladLabel.setText(csl.pobierzBlad());
            BladDialog.setVisible(true);
        }
    }
}//GEN-LAST:event_ZalogujButtonActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        bladLabel.setText(csl.pobierzBlad());
        BladDialog.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void wylogujButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wylogujButtonActionPerformed
        csl.wyloguj();
        bladLabel.setText("Zostałeś wylogowany");
        BladDialog.setVisible(true);
        loginPanel.setVisible(true);
        zalogowanyPanel.setVisible(false);
    }//GEN-LAST:event_wylogujButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(BibliotekaSzkolna.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(BibliotekaSzkolna.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(BibliotekaSzkolna.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(BibliotekaSzkolna.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new BibliotekaSzkolna().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog BladDialog;
    private javax.swing.JTextField LoginTextField;
    private javax.swing.JPasswordField PasswordField;
    private javax.swing.JButton ZalogujButton;
    private javax.swing.JLabel bladLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel loginPanel;
    private javax.swing.JButton wylogujButton;
    private javax.swing.JLabel zalogowanyLabel;
    private javax.swing.JPanel zalogowanyPanel;
    // End of variables declaration//GEN-END:variables
}
